package com.bdqn.ch07.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    private String[] excludePathPatterns;

    //定义拦截器的规则
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        System.out.println("初始化InterceptorConfig................................");
        String[] pathPatterns = {"/**"}; //拦截路径规则，首先拦截所有的东西
        String[] excludePathPatterns = {"/FirstServlet","/secondServlet","/","/error","/login","/dologin","/css/**","/fonts/**","/images/**","/js/**","/localcss/**","/localjs/**"}; //排除路径规则
        registry.addInterceptor(new AuthorizationInterceptor()) //注册拦截器，拦截器的具体实现
                .addPathPatterns(pathPatterns) //添加路径规则，首先拦截所有的东西
                .excludePathPatterns(excludePathPatterns); //添加排除路径规则
    }
}
